package com.sinosoft.brokerchannel.rest;

import com.sinosoft.brokerchannel.base.annotation.MyResponseBody;
import com.sinosoft.brokerchannel.base.common.SystemParamFinal;
import com.sinosoft.brokerchannel.base.rest.AbstractController;
import com.sinosoft.brokerchannel.base.server.LogService;
import com.sinosoft.brokerchannel.base.utile.BusinessException;
import com.sinosoft.brokerchannel.entity.vo.CarActualValueCalculationRequest;
import com.sinosoft.brokerchannel.entity.vo.CarActualValueCalculationResponse;
import com.sinosoft.brokerchannel.server.CarActualValueCalculationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * 需求名称：[保险经纪渠道平台]<br/>
 *
 * @author gzj
 * @version V1.0
 * @date 2018-8-21 10:48
 * 车辆实际价值计算
 */
@Api(value = "services", description = "车险渠道平台车辆实际价值计算")
@Controller
@RequestMapping("/caractualvalue")
public class CarActualValueController extends AbstractController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private LogService logService;
    @Autowired
    private CarActualValueCalculationService carActualValueCalculationService;
    @RequestMapping(value = "actualvaluecalculation", method = RequestMethod.POST, produces = {"application/xml;charset=UTF-8", "application/json;charset=UTF-8"}, consumes = {"application/xml;charset=UTF-8", "application/json;charset=UTF-8"})
    @ApiOperation(value = "实际价值计算", notes = "实际价值计算", position = 1)
    @ApiResponses({@ApiResponse(code = 400, message = "失败")})
    @MyResponseBody
    public CarActualValueCalculationResponse actualvaluecalculation(@RequestBody CarActualValueCalculationRequest request) throws Exception {
        String flowid = null;
        CarActualValueCalculationResponse response = null;
        try {
            super.init("实际价值计算", request.getRequestHead());// 初始化日志
            flowid = super.beforeTheTransaction(request);// 记录日志
            response = carActualValueCalculationService.carActualValueCalculation(request);// 调用服务
            super.sucessAction();
        } catch (BusinessException e) {
            logger.info(SystemParamFinal.Exception_LOG, e);
            super.businessExceptionAction(e);
        } catch (Exception e) {
            logger.info(SystemParamFinal.Exception_LOG, e);
            super.exceptionAction(e);
        } finally {
            if (response == null) {
                response = new CarActualValueCalculationResponse();
            }
            response.setResponseHead(super.getResponseHead());
            super.afterTheTransaction(response, flowid);// 回写日志
        }
        return response;
    }
}
